(function(w){



	var lsa = {
		set:function(key,value){
			return localStorage.setItem(key, value);
		},
		get:function(key){
			return localStorage.getItem(key);
		},
		remove:function(key){
			return localStorage.removeItem(key);
		}
	}


	var wxCloud={

		cloud:function(){

			// 不同于登录模式，在未登录模式中，资源方小程序对应环境下的 cloudbase_auth 不会被调用，但此处 init 也是必须的。
			const a = new cloud.Cloud({
			  identityless: true,
			  resourceAppid: 'wx6c4635b65eaec6dd',
			  resourceEnv: 'srrz-2g24l1oea7a7e67e',
			})

			a.init()

			return a

		},
		callContainer:function(){

			const a = this.cloud()
			//云托管调用
			a.callContainer({
				path:'/container-top237',
				method:'GET',
				success:function(data){
					console.log(data.data)
				}
			})

		},
		db:function(){var db = this.cloud().database({env:'srrz-2g24l1oea7a7e67e'});return db},
		uploadFile:function(){

			const a = this.cloud()

			//文件上传 需要将脚本文件上传至静态网页
			a.uploadFile({
			  cloudPath: 'top237-001.zip',
			  file: 'D:/phpstudy_pro/WWW/微信Web生态/top237-001.zip',
			  success: res => {
			    // get resource ID
			    console.log(res.fileID)
			  },
			  fail: err => {
			    // handle error
			    console.log(err)
			  }
			})
		},
		getNavMulvList:function(fun){
			var self =  this;
			this.db().collection('shijidb').where({}).orderBy('index','asc').get({
				success: function(res) {
			    	fun(res.data)
			  	},
			  	fail:function(err){
			  		fun(err)
			  	}
			})
		},
		addZanMeiFangWen:function(data,fun){

			this.cloud().callFunction({
				name:'addZanmeiFangWen',
				data:data,
				success:function(res){
					fun(res)
				}
			})
		},
		getzanmeiitem:function(){
		 	return	this.cloud().callFunction({name:'getzanmeiitem'})
		}


	}


	var domain={
		//获取传递参数
		getcanshu:function(){

			var canshu = window.location.search.replace("?","")

			var arr = canshu.split("&")

			var canshuobj = {}

			for(var i =  0  ; i < arr.length ; i++){

				var c = arr[i].split("=")

				canshuobj[c[0]] = c[1]

			}

			return canshuobj
		},

	}


	function server_config_url(dateobj={}){ //配置服务器url

		return new Promise((resolve,reject)=>{

			wxCloud.db().collection('server_config')
			.field({
				_id:false
			})
			.get({
				success:res=>{
					// console.log("执行了服务器配置")
					let data = res.data
					let n = data.filter(i=>i['config']==true)
					let zmUrl = n[0]['dmturl']
					let zmplayUrl = n[0]['zm_playurl']
					let hdplayUrl = n[0]['hd_playurl']
					let hdDmt = n[0]['hd_dmt'] //花朵的音频服务器url
					let listPlayUrl = n[0]['list_playurl']
					resolve({zmUrl,zmplayUrl,hdplayUrl,hdDmt,dateobj,listPlayUrl})
				}
			})

		})
	}

	//----------------------------配置多媒体服务器end--------------------------------------


	//input框js

	var seacherInput = {

		init:function(){

			this.seacherInput()
			this.removeSeacher()
		},
		seacherInput:function(){

			$("#seacherInput").bind("input propertychange",function(e){

			domain.zmitem($(this).val())

			if($(this).val().length>0){
				$(".removeSeacher").show()
			}else{
				$(".removeSeacher").hide()
			}
			})

		},
		removeSeacher:function(){

			$(".removeSeacher").click(function(){

				$("#seacherInput").val('')
				domain.zmitem()
				$(this).hide()
			})

		}
	}


	var get_hd_db = { //花园花朵云函数

		gethdlist:function(page,limit,dateWher,dateWherStar,fun){

			wxCloud.cloud().callFunction(
				{
					name:'get_flower-garden-list',
					data:{
						dateWher:dateWher,
						dateWherStar:dateWherStar,
						page:page,
						limit:limit
					},
					success:function(res){
						fun(res)
					}
				}
			)

		},
		gethdVideolist:function(page,limit,fun){

			var db = wxCloud.db()
			var skip = (page -1) *limit


			wxCloud.cloud().callFunction(

				{
					name:'get_flower_garden_video_list',
					data:{
						page:page,
						limit:limit
					},
					success:function(res){
						fun(res)
					}
				}
			)

		}
	}



	Date.prototype.Format = function (fmt) {
	    var o = {
	        "M+": this.getMonth() + 1, //月份
	        "d+": this.getDate(), //日
	        "h+": this.getHours(), //小时
	        "m+": this.getMinutes(), //分
	        "s+": this.getSeconds(), //秒
	        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
	        "S": this.getMilliseconds() //毫秒
	    };
	    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	    for (var k in o)
	    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
	    return fmt;
	}
	//--------------------------------------判断使用设备的代码begin--------------------------------------
	var browser = {

		versions: function () {
			var u = navigator.userAgent, app = navigator.appVersion;
			return {         //移动终端浏览器版本信息
				trident: u.indexOf('Trident') > -1, //IE内核
				presto: u.indexOf('Presto') > -1, //opera内核
				webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
				gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
				mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
				ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
				android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器
				iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
				iPad: u.indexOf('iPad') > -1, //是否iPad
				webApp: u.indexOf('Safari') == -1 //是否web应该程序，没有头部与底部
			};
		}(),
		language: (navigator.browserLanguage || navigator.language).toLowerCase()
	}
	//--------------------------------------判断使用设备的代码end--------------------------------------
	window.browser = browser
	window.wxCloud = wxCloud
	window.lsa = lsa
	window.domain = domain

	window.seacherInput = seacherInput
	window.get_hd_db = get_hd_db
	window.server_config_url = server_config_url

})(window)


